package com.lepu.app.usercenter;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;

import com.core.lib.adapter.FragmentPageAdapter;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.widget.MenuBarView;
import com.core.lib.widget.MenuBarView.OnMenuBarListener;
import com.core.lib.widget.NoScrollViewPager;
import com.lepu.app.usercenter.fragment.FragmentPwdMobile;
import com.lepu.app.usercenter.fragment.FragmentPwdQuestion;
import com.lepu.app.usercenter.fragment.FragmentPwdTell;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.pasm.R;

public class ForgetPwdActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener ,OnMenuBarListener{

	private static final int TAB_COUNT = 3;

	private static ForgetPwdActivity mInstance = null;
	private NoScrollViewPager mViewPager = null;
	private MenuBarView mMenuBarView = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.usercenter_forget_pwd_activity);

		mInstance = this;
		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		
		mInstance = null;
	}
	
	public static ForgetPwdActivity getInstance()
	{
		return mInstance;
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}

	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("找回密码");
		topbar.setonTopbarNewLeftLayoutListener(this);

		// content
		FragmentPwdMobile fragmentOne = new FragmentPwdMobile();
		FragmentPwdQuestion fragmentTwo = new FragmentPwdQuestion();
		FragmentPwdTell fragmentThree = new FragmentPwdTell();

		ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
		fragmentList.add(fragmentOne);
		fragmentList.add(fragmentTwo);
		fragmentList.add(fragmentThree);

		mViewPager = (NoScrollViewPager) findViewById(R.id.viewPager);
		mViewPager.setAdapter(new FragmentPageAdapter(
				getSupportFragmentManager(), fragmentList, null, null));
		// 是否可以滑动更新tab
		mViewPager.setNoScroll(false);
		mViewPager.setOnPageChangeListener(new MyViewChangeListener());

		mViewPager.setOffscreenPageLimit(TAB_COUNT - 1);

		// menubar
		mMenuBarView = (MenuBarView) findViewById(R.id.menuBar);
		mMenuBarView.setOnMenuBarListener(this);
		mMenuBarView.setSelectedIndex(0);
	}

	public int getMainMenuSelected() {
		return mViewPager.getCurrentItem();
	}
	
	/*
	 * 暂时不使用
	 */
	class MyViewChangeListener implements OnPageChangeListener {

		@Override
		public void onPageScrollStateChanged(int arg0) {

		}

		@Override
		public void onPageScrolled(int position, float positionOffset, int arg2) {

		}

		@Override
		public void onPageSelected(int index) {
			mMenuBarView.setSelectedIndex(index);
		}
	}

	@Override
	public void onMenuBarItemSelected(int menuIndex,View view) {
		if (menuIndex == getMainMenuSelected())
			return;

		mViewPager.setCurrentItem(menuIndex);
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}
}
